package b.b.a.b;

import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;

public class b<K, V> implements Iterable<Map.Entry<K, V>> {

    /* renamed from: b  reason: collision with root package name */
    c<K, V> f1144b;

    /* renamed from: c  reason: collision with root package name */
    private c<K, V> f1145c;

    /* renamed from: d  reason: collision with root package name */
    private WeakHashMap<f<K, V>, Boolean> f1146d = new WeakHashMap<>();
    private int e = 0;

    static class a<K, V> extends e<K, V> {
        a(c<K, V> cVar, c<K, V> cVar2) {
            super(cVar, cVar2);
        }

        /* access modifiers changed from: package-private */
        public c<K, V> b(c<K, V> cVar) {
            return cVar.e;
        }

        /* access modifiers changed from: package-private */
        public c<K, V> c(c<K, V> cVar) {
            return cVar.f1149d;
        }
    }

    /* renamed from: b.b.a.b.b$b  reason: collision with other inner class name */
    private static class C0031b<K, V> extends e<K, V> {
        C0031b(c<K, V> cVar, c<K, V> cVar2) {
            super(cVar, cVar2);
        }

        /* access modifiers changed from: package-private */
        public c<K, V> b(c<K, V> cVar) {
            return cVar.f1149d;
        }

        /* access modifiers changed from: package-private */
        public c<K, V> c(c<K, V> cVar) {
            return cVar.e;
        }
    }

    static class c<K, V> implements Map.Entry<K, V> {

        /* renamed from: b  reason: collision with root package name */
        final K f1147b;

        /* renamed from: c  reason: collision with root package name */
        final V f1148c;

        /* renamed from: d  reason: collision with root package name */
        c<K, V> f1149d;
        c<K, V> e;

        c(K k, V v) {
            this.f1147b = k;
            this.f1148c = v;
        }

        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof c)) {
                return false;
            }
            c cVar = (c) obj;
            return this.f1147b.equals(cVar.f1147b) && this.f1148c.equals(cVar.f1148c);
        }

        public K getKey() {
            return this.f1147b;
        }

        public V getValue() {
            return this.f1148c;
        }

        public int hashCode() {
            return this.f1147b.hashCode() ^ this.f1148c.hashCode();
        }

        public V setValue(V v) {
            throw new UnsupportedOperationException("An entry modification is not supported");
        }

        public String toString() {
            return this.f1147b + "=" + this.f1148c;
        }
    }

    private class d implements Iterator<Map.Entry<K, V>>, f<K, V> {

        /* renamed from: b  reason: collision with root package name */
        private c<K, V> f1150b;

        /* renamed from: c  reason: collision with root package name */
        private boolean f1151c = true;

        d() {
        }

        public void a(c<K, V> cVar) {
            c<K, V> cVar2 = this.f1150b;
            if (cVar == cVar2) {
                c<K, V> cVar3 = cVar2.e;
                this.f1150b = cVar3;
                this.f1151c = cVar3 == null;
            }
        }

        /* renamed from: b */
        public Map.Entry<K, V> next() {
            c<K, V> cVar;
            if (this.f1151c) {
                this.f1151c = false;
                cVar = b.this.f1144b;
            } else {
                c<K, V> cVar2 = this.f1150b;
                cVar = cVar2 != null ? cVar2.f1149d : null;
            }
            this.f1150b = cVar;
            return this.f1150b;
        }

        public boolean hasNext() {
            if (this.f1151c) {
                return b.this.f1144b != null;
            }
            c<K, V> cVar = this.f1150b;
            return (cVar == null || cVar.f1149d == null) ? false : true;
        }
    }

    private static abstract class e<K, V> implements Iterator<Map.Entry<K, V>>, f<K, V> {

        /* renamed from: b  reason: collision with root package name */
        c<K, V> f1153b;

        /* renamed from: c  reason: collision with root package name */
        c<K, V> f1154c;

        e(c<K, V> cVar, c<K, V> cVar2) {
            this.f1153b = cVar2;
            this.f1154c = cVar;
        }

        private c<K, V> e() {
            c<K, V> cVar = this.f1154c;
            c<K, V> cVar2 = this.f1153b;
            if (cVar == cVar2 || cVar2 == null) {
                return null;
            }
            return c(cVar);
        }

        public void a(c<K, V> cVar) {
            if (this.f1153b == cVar && cVar == this.f1154c) {
                this.f1154c = null;
                this.f1153b = null;
            }
            c<K, V> cVar2 = this.f1153b;
            if (cVar2 == cVar) {
                this.f1153b = b(cVar2);
            }
            if (this.f1154c == cVar) {
                this.f1154c = e();
            }
        }

        /* access modifiers changed from: package-private */
        public abstract c<K, V> b(c<K, V> cVar);

        /* access modifiers changed from: package-private */
        public abstract c<K, V> c(c<K, V> cVar);

        /* renamed from: d */
        public Map.Entry<K, V> next() {
            c<K, V> cVar = this.f1154c;
            this.f1154c = e();
            return cVar;
        }

        public boolean hasNext() {
            return this.f1154c != null;
        }
    }

    interface f<K, V> {
        void a(c<K, V> cVar);
    }

    public Iterator<Map.Entry<K, V>> a() {
        C0031b bVar = new C0031b(this.f1145c, this.f1144b);
        this.f1146d.put(bVar, Boolean.FALSE);
        return bVar;
    }

    public Map.Entry<K, V> b() {
        return this.f1144b;
    }

    /* access modifiers changed from: protected */
    public c<K, V> c(K k) {
        c<K, V> cVar = this.f1144b;
        while (cVar != null && !cVar.f1147b.equals(k)) {
            cVar = cVar.f1149d;
        }
        return cVar;
    }

    public b<K, V>.d d() {
        b<K, V>.d dVar = new d();
        this.f1146d.put(dVar, Boolean.FALSE);
        return dVar;
    }

    public Map.Entry<K, V> e() {
        return this.f1145c;
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof b)) {
            return false;
        }
        b bVar = (b) obj;
        if (size() != bVar.size()) {
            return false;
        }
        Iterator it = iterator();
        Iterator it2 = bVar.iterator();
        while (it.hasNext() && it2.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            Object next = it2.next();
            if ((entry == null && next != null) || (entry != null && !entry.equals(next))) {
                return false;
            }
        }
        return !it.hasNext() && !it2.hasNext();
    }

    /* access modifiers changed from: protected */
    public c<K, V> f(K k, V v) {
        c<K, V> cVar = new c<>(k, v);
        this.e++;
        c<K, V> cVar2 = this.f1145c;
        if (cVar2 == null) {
            this.f1144b = cVar;
        } else {
            cVar2.f1149d = cVar;
            cVar.e = cVar2;
        }
        this.f1145c = cVar;
        return cVar;
    }

    public V g(K k, V v) {
        c c2 = c(k);
        if (c2 != null) {
            return c2.f1148c;
        }
        f(k, v);
        return null;
    }

    public V h(K k) {
        c c2 = c(k);
        if (c2 == null) {
            return null;
        }
        this.e--;
        if (!this.f1146d.isEmpty()) {
            for (f<K, V> a2 : this.f1146d.keySet()) {
                a2.a(c2);
            }
        }
        c<K, V> cVar = c2.e;
        if (cVar != null) {
            cVar.f1149d = c2.f1149d;
        } else {
            this.f1144b = c2.f1149d;
        }
        c<K, V> cVar2 = c2.f1149d;
        if (cVar2 != null) {
            cVar2.e = c2.e;
        } else {
            this.f1145c = c2.e;
        }
        c2.f1149d = null;
        c2.e = null;
        return c2.f1148c;
    }

    public int hashCode() {
        Iterator it = iterator();
        int i = 0;
        while (it.hasNext()) {
            i += ((Map.Entry) it.next()).hashCode();
        }
        return i;
    }

    public Iterator<Map.Entry<K, V>> iterator() {
        a aVar = new a(this.f1144b, this.f1145c);
        this.f1146d.put(aVar, Boolean.FALSE);
        return aVar;
    }

    public int size() {
        return this.e;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        Iterator it = iterator();
        while (it.hasNext()) {
            sb.append(((Map.Entry) it.next()).toString());
            if (it.hasNext()) {
                sb.append(", ");
            }
        }
        sb.append("]");
        return sb.toString();
    }
}
